<?php
define('ROOT_DIR', $_SERVER['DOCUMENT_ROOT'].'/');
$path = ROOT_DIR.'setting.php';
$settingsContent = file_get_contents($path);
$smtp_host = $_POST['smtp_host'];
$smtp_port = $_POST['smtp_port'];
$smtp_secure = $_POST['smtp_secure'];
$smtp_user = $_POST['smtp_user'];
$newSettingMailArray = <<<EOT
\$rainyun_oss = array(
    'access_key_id' => '$smtp_host',
    'access_key_secret' => '$smtp_port',
    'bucket' => '$smtp_secure',
    'endpoint' => '$smtp_user'
);
EOT;
$pattern = '/\$rainyun_oss\s*=\s*array\s*\(\s*[^;]*\s*\);/s';
$replacement = $newSettingMailArray;
$updatedSettingsContent = preg_replace($pattern, $replacement, $settingsContent);
file_put_contents($path, $updatedSettingsContent);
echo '<script>alert("修改成功");window.location.href="../../pzsetting.php?s=oss";</script>';